import { getSpaceApi, getResourceApi, realNameApi, getIncomeApi, smsCodeApi } from "../../utils/serviceApiUrl.js";
const STORAGE_SPACE_LIST = "STORAGE_SPACE_LIST";
const INCOME_LIST = "INCOME_LIST";
const state = {
    storageSpaceList: null,
    incomList: null
};

const getters = {
    storageSpaceList(state) {
        return state.storageSpaceList;
    },
    incomList(state) {
        return state.incomList;
    }
};

const actions = {
    getIncomeList({ commit }, param) {
        getIncomeApi(param).then((res) => {
            if (res.code == 0) {
                commit(INCOME_LIST, res);
            }
        });
    },
    getStorageSpaceList({ commit }, param) {
        getSpaceApi(param).then((res) => {
            if (res.code == 0) {
                commit(STORAGE_SPACE_LIST, res);
            }
        });
    },
    // eslint-disable-next-line no-unused-vars
    smsCode({ commit }, param) {
        return new Promise((resolve, reject) => {
            smsCodeApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    },
    // eslint-disable-next-line no-unused-vars
    uploadResource({ commit }, param) {
        return new Promise((resolve, reject) => {
            getResourceApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    },
    // eslint-disable-next-line no-unused-vars
    accountRealName({ commit }, param) {
        return new Promise((resolve, reject) => {
            realNameApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    }
};
const mutations = {
    [STORAGE_SPACE_LIST](state, data) {
        state.storageSpaceList = data.rs;
    },
    [INCOME_LIST](state, data) {
        state.incomList = data.rs;
    }
};

export default {
    state,
    getters,
    actions,
    mutations
};
